package top.lyjwn.todo.common.utils;

import java.util.Random;

/**
 * @author luoyujie
 */
public class RandomValue {
    /**
     * 随机字符串生成
     *
     * @param length
     * @return
     */
    public static String getRandomString(int length) { // length表示生成字符串的长度
        String base = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }

    /**
     * 生成随机数
     *
     * @param min
     * @param max
     * @return
     */
    public static int getRandomNumber(int min, int max) {
        Random random = new Random();
        return random.nextInt(max + 1 - min) + min;
    }


    /**
     * 生成随机数
     *
     * @param max
     * @return
     */
    public static int getRandomNumber(int max) {
        return getRandomNumber(0, max);
    }

    /**
     * 生成随机｛数字字符串｝
     *
     * @param length 生成的｛数字字符串｝长度
     * @return
     */
    public static String getRandomNumberString(int length) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i=0;i<length;i++){
            stringBuilder.append(getRandomNumber(0,9));
        }
        return stringBuilder.toString();
    }
}
